Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload routes when changed #501

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Oct 31, 2024

No description provided.

@andyw8 andyw8 force-pushed the andyw8/reload-routes-when-changed branch from ff848d9 to 003e017 Compare October 31, 2024 16:31
@andyw8 andyw8 force-pushed the andyw8/reload-routes-when-changed branch from 003e017 to 34356a2 Compare October 31, 2024 16:48
@andyw8 andyw8 force-pushed the andyw8/reload-routes-when-changed branch from 30a8a50 to 8944ed6 Compare November 1, 2024 17:45
private

def response
_headers, content = @stdout.string.split("\r\n\r\n")
Copy link
Contributor Author

@andyw8 andyw8 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change to handle making multiple requests.

JSON.parse(content, symbolize_names: true)
headers, content = @stdout.string.split("\r\n\r\n")
content_length = headers[/Content-Length: (\d+)/i, 1].to_i
# binding.break
Copy link
Contributor Author

@andyw8 andyw8 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock I'm trying to figure out what's happening here: If I add the breakpoint, and call @stdout.string = "" each time, it passes. But I call it from the code it fails with not opened for writing (IOError).

change[:uri].end_with?("db/schema.rb") || change[:uri].end_with?("structure.sql")
end
schema = lambda { |change| change[:uri].end_with?("db/schema.rb") || change[:uri].end_with?("structure.sql") }
routes = lambda { |change| change[:uri].end_with?("routes.rb") || change[:uri].match?("routes/**/*.rb") }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to simplify the conditional.

@@ -141,7 +144,7 @@ def register_additional_file_watchers(global_state:, outgoing_queue:)
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
watchers: [
Interface::FileSystemWatcher.new(
glob_pattern: "**/*structure.sql",
glob_pattern: "**/*structure.sql,**/*routes.rb,routes/**/*.rb",
Copy link
Contributor Author

@andyw8 andyw8 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should cover almost any way that people set up the Rails routes, but there is a risk of a false positive if someone is using the term routes for something else in their app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 but I wonder if we can ask Rails where all the routes files are...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly:

dummy(dev)> Rails.application.routes.draw_paths.map(&:to_s)
=> 
["/Users/andyw8/.gem/ruby/3.3.0/gems/actionview-8.0.0.beta1/config/routes",
 "/Users/andyw8/.gem/ruby/3.3.0/gems/activestorage-8.0.0.beta1/config/routes",
 "/Users/andyw8/.gem/ruby/3.3.0/gems/actioncable-8.0.0.beta1/config/routes",
 "/Users/andyw8/.gem/ruby/3.3.0/gems/actionmailbox-8.0.0.beta1/config/routes",
 "/Users/andyw8/.gem/ruby/3.3.0/gems/actiontext-8.0.0.beta1/config/routes",
 "/Users/andyw8/src/github.com/Shopify/ruby-lsp-rails/test/dummy/config/routes",
 "/Users/andyw8/src/github.com/Shopify/ruby-lsp-rails/test/dummy/config/routes"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant